package com.example.demo.mapper;


import com.example.demo.pojo.Recharge;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RechargeMapper {

//    @Select("select * from  recharge_records where userid = #{userid}")
//    List<Recharge> findByuserid(int userid);

    @Select("insert into recharge_records(rechargetime,paymentmethod,amount,balanceafter,userid,payid) values (now(),#{paymentmethod},#{amount},#{balanceafter},#{userid},#{payid})")
    void add(String paymentmethod, double amount,double balanceafter, int userid,String payid);

    List<Recharge> findByUserid(int userid);

    List<Recharge> findByrealname(String realname);

    @Select("select RR.*,U.realname from recharge_records RR JOIN user U ON RR.userid=U.userid where recordid=#{recordid}")
    Recharge getByrecordid(Integer recordid);

    @Delete("delete from recharge_records where recordid=#{recordid} and paystatus=0")
    void deleterecharge(Integer recordid);

    @Update("update recharge_records set paystatus = 2 where recordid=#{recordid} and paystatus=0")
    void cancelrecharge(Integer recordid);

    @Select("select * from recharge_records where payid=#{payid}")
    Recharge getBypayid(String payid);

    @Update("update recharge_records set paystatus = 1 where recordid=#{recordid}")
    void updatestatus(Integer recordid);
}
